package com.example.leero.graduation.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.leero.graduation.R;
import com.example.leero.graduation.Util.DateUtil;
import com.example.leero.graduation.Util.ImageLoader;
import com.example.leero.graduation.Util.StringUtil;
import com.example.leero.graduation.activity.DetailActivity;
import com.example.leero.graduation.activity.FriendActivity;
import com.example.leero.graduation.model.ActItem;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

/**
 * Created by Leero on 2017-4-22.
 */

public class ActivityItemDelegate implements ItemViewDelegate<ActItem> {
    private Context context;

    public ActivityItemDelegate(Context context) {
        this.context = context;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_list_loaction;
    }

    @Override
    public boolean isForViewType(ActItem item, int position) {
        return true;
    }

    @Override
    public void convert(ViewHolder holder, final ActItem actItem, int position) {
        RelativeLayout item = holder.getView(R.id.item);
        LinearLayout ll_avatar = holder.getView(R.id.avatar);
        TextView title = holder.getView(R.id.tv_active_name);
        TextView time = holder.getView(R.id.tv_active_time);
        TextView address = holder.getView(R.id.tv_active_address);
        TextView name = holder.getView(R.id.tv_active_sponsor);
        ImageView avatar = holder.getView(R.id.iv_avatar);
//        ImageView active_status = holder.getView(R.id.iv_active_status);

        if (!StringUtil.isEmpty(actItem.user_icon)) {
            ImageLoader.load(context, avatar, actItem.user_icon);
        } else {
            avatar.setImageResource(R.drawable.default_avatar_cricle);
        }

        title.setText(actItem.title);
        time.setText(DateUtil.getDateStringFromTZ(actItem.start_time));
        address.setText(actItem.address);
        name.setText(actItem.user_name);

        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DetailActivity.class);
                intent.putExtra("id", actItem.act_id);
                context.startActivity(intent);
            }
        });

        ll_avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, FriendActivity.class);
                intent.putExtra("id", actItem.user_id);
                intent.putExtra("isNew", false);
                context.startActivity(intent);
            }
        });
    }
}
